package com.guigu.chenjiajun.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.chenjiajun.service.NewProductionPlanRegistrationService;
import com.guigu.common.mapper.DFileMapper;
import com.guigu.common.mapper.MApplyMapper;
import com.guigu.common.pojo.DFile;
import com.guigu.common.pojo.MApply;
import com.guigu.common.util.GetUUidUtil;
import com.guigu.common.vo.SearchVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 新发生生产计划登记
 */
@Service
public class NewProductionPlanRegistrationServiceImpl implements NewProductionPlanRegistrationService {


    @Resource
    private DFileMapper dFileMapper;

    @Resource
    private MApplyMapper mapper;

    @Resource
    private GetUUidUtil getUUidUtil;

    @Override
    public SearchVo<DFile> queryPlanDFile(SearchVo searchVo) {
        PageHelper.startPage(searchVo.getPageNumber(),searchVo.getPageSize());
        PageInfo p=new PageInfo(this.dFileMapper.queryPlanDfile(searchVo));
        searchVo.setRows(p.getList());
        searchVo.setTotal(p.getTotal());
        return searchVo;
    }

    @Override
    public DFile queryById(String id) {
        return this.dFileMapper.queryById(id);
    }

    @Override
    public int addApply(List<MApply> mapplies) {
        List<Boolean> i1=new ArrayList();
        String s = getUUidUtil.returnId("300");
        for (int i=0;i<mapplies.size();i++){
            mapplies.get(i).setApplyId(s);
            mapplies.get(i).setCheckTag("s001-0");
            mapplies.get(i).setManufactureTag("p001-0");
            int i2 = this.mapper.insertSelective(mapplies.get(i));
            i1.add(i2>0);
        }
        int a ;
            if (i1.contains(false)){
                a=0;
            }else {
                a=1;
            }
        return a;
    }
}
